/*
 * navinode.cpp
 *
 *  Created on: 30/11/2011
 *      Author: Aeradon
 */

#include "../include/navinode.hpp"
#include "../include/face.hpp"

unsigned int NaviNode::markCount = 1;

NaviNode::NaviNode(Face *face) :
	face(face),
	x(0),
	y(0),
	mark(0),
	f(0),
	g(0),
	h(0),
	p(nullptr),
	vecIndex(0),
	n_open(0)
{
	n[0] = nullptr;
	n[1] = nullptr;
	n[2] = nullptr;

	// Calculate the center of the triangle
	T x1 = PFR_MAX_FLOAT, y1 = PFR_MAX_FLOAT;
	T x2 = 0, y2 = 0;
	for (int i = 0; i < face->getEdgeCount(); i++)
	{
		if(face->getEdge(i)->vtx()->x < x1)
			x1 = face->getEdge(i)->vtx()->x;
		if(face->getEdge(i)->vtx()->x > x2)
			x2 = face->getEdge(i)->vtx()->x;
		if(face->getEdge(i)->vtx()->y < y1)
			y1 = face->getEdge(i)->vtx()->y;
		if(face->getEdge(i)->vtx()->y > y2)
			y2 = face->getEdge(i)->vtx()->y;
	}
	x = (x1 + x2)/(T)2;
	y = (y1 + y2)/(T)2;
}

NaviNode::~NaviNode()
{

}

NaviNode::T NaviNode::X()
{
	return (x);
}

NaviNode::T NaviNode::Y()
{
	return (y);
}

Point<NaviNode::T> NaviNode::Pos()
{
	return Point<T>(x,y);
}

bool NaviNode::IsMarked()
{
	return (mark == markCount);
}

void NaviNode::ResetMark()
{
	++markCount;
	if (markCount > 0xFFFFFFF0)
		markCount = 1;
}

void NaviNode::Mark()
{
	mark = markCount;
}
